package com.lzq.mybatis.binding;
import com.lzq.mybatis.session.sqlSession;
import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.util.Collection;

public class MapperProxy implements InvocationHandler {
    private sqlSession session;
    public MapperProxy(sqlSession session) {
        this.session = session;
    }

    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
        //如果是Collection的子类，那么就调用selectList否则就调用selectOne
        if(Collection.class.isAssignableFrom(method.getReturnType())){
            return session.selectList(method.getDeclaringClass().getName()+"."+method.getName(),args == null?null:args[0]);
        }else{
            return session.selectOne(method.getDeclaringClass().getName()+"."+method.getName(),args == null?null:args[0]);
        }
    }
}
